﻿using CanDichVu.Db;
using CanDichVu.FrameWork.Conrtron;
using CanDichVu.Service.Iservice;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CanDichVU.Areas.Admin.Controllers
{

    public class Ad_UserController : ContronllerBase
    {
        private readonly IRoles _IRoles;

        public Ad_UserController(IRoles iRoles)
        {
            this._IRoles = iRoles;
        }

        //
        // GET: /Admin/Ad_User/

        public ActionResult IndexRoles()
        {
            return View();
        }

        public ActionResult _ListRoles()
        {
            var listR = _IRoles.List();
            var jsonResult = Json(listR, JsonRequestBehavior.AllowGet);
            jsonResult.MaxJsonLength = int.MaxValue;
            return jsonResult;
        }

        public ActionResult AddRoles()
        {
            try
            {
                var Name = Request["models[0][Name]"];
                var Access = Request["models[0][Access]"];

                Role tt = new Role();
                tt.Id = 0;
                tt.Name = Name;
                tt.Access = int.Parse(Access);
                tt.DateCreate = DateTime.Now ;
                _IRoles.addOrupdate(tt);

                return Json(true, JsonRequestBehavior.AllowGet);
            }
            catch { return Json(false, JsonRequestBehavior.AllowGet); }
        }

        public ActionResult UpdateRoles()
        {
            try
            {
                var Id = Request["models[0][Id]"];
                var Name = Request["models[0][Name]"];
                var Access = Request["models[0][Access]"];

                Role tt = _IRoles.GetById(int.Parse(Id));
                tt.Name = Name;
                tt.Access = int.Parse(Access);
                _IRoles.addOrupdate(tt);

                return Json(true, JsonRequestBehavior.AllowGet);
            }
            catch { return Json(false, JsonRequestBehavior.AllowGet); }
        }
    }
}
